Page({
  data: {
    garbageClassfyList:[],
    garbageList:[],
    curNav: 1,
    curIndex: 0
  },
  onShow(){
    this.getGarbageClassfyList()
  },
  getGarbageClassfyList(){
    wx.cloud.callFunction({
      name: "db",
      data: {
        $url: "getGarbageClassfyList"
      }
    }).then(res => {
      let result = res.result
      if (result.code) {
        this.setData({
          garbageClassfyList: result.data
        })
        this.getGarbageList(result.data[0]._id)
      }
    })
  },
  getGarbageList(class_id){
    wx.cloud.callFunction({
      name: "db",
      data: {
        $url: "getGarbageList",
        class_id:class_id,
        page:1,
        limit:10
      }
    }).then(res => {
      let result = res.result
      if (result.code) {
        this.setData({
          garbageList: result.data
        })
      }
    })
  },
  //事件处理函数  
  switchRightTab: function (e) {
    // 获取item项的id，和数组的下标值  
    let id = e.target.dataset.id,
      index = parseInt(e.target.dataset.index);
    // 把点击到的某一项，设为当前index  
    this.setData({
      curNav: id,
      curIndex: index
    })
    this.getGarbageList(id)
  }
})  